package svgedit.TestSVG;

import static org.junit.Assert.assertTrue;
import org.junit.Test;
import svgedit.gui.Frame;
import svgedit.svg.SVGDocument;
import svgedit.svg.SVGLineElement;
import svgundoredo.AddElementCommand;

/**
 * test AddElementCommand class
 */

public class AddElementCommandTest
{
    
    /**
     * test execute() method
     */
    @Test
    public void testexecute()
    {
        // creat new frame
        Frame frame = new Frame();
        SVGDocument document;
        document = frame.getDocument();
        SVGLineElement element = new SVGLineElement(document);
        AddElementCommand add = new AddElementCommand(document, element);
        // the group is empty
        assertTrue(document.getRootGroup().getChildren().length == 0);
        add.execute();
        // the group is added one element after execute
        assertTrue(document.getRootGroup().getChildren().length == 1);
        
    }
    
    /**
     * test undo() method
     */
    @Test
    public void testundo()
    {
        // creat new frame
        Frame frame = new Frame();
        SVGDocument document;
        document = frame.getDocument();
        SVGLineElement element = new SVGLineElement(document);
        AddElementCommand add = new AddElementCommand(document, element);
        // the group is empty
        assertTrue(document.getRootGroup().getChildren().length == 0);
        add.execute();
        // the group is added one element after execute
        assertTrue(document.getRootGroup().getChildren().length == 1);
        // undo it, the group become empty
        add.undo();
        assertTrue(document.getRootGroup().getChildren().length == 0);
        
    }
}
